package com.hu.hutool;

import cn.hutool.cron.CronUtil;
import com.commons.tools.exception.BaseExceptionHandler;
import com.hu.hutool.ThreadUtil.ThreadPoolExecutorTest;
import com.hu.hutool.xxl_job.XxlJobHandleSecond;
import com.xxl.job.core.executor.XxlJobExecutor;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@Slf4j
@EnableDiscoveryClient
@MapperScan("com.hu.hutool.dao")
@ComponentScan(basePackages = {"com.commons.tools.**",
        "com.commons.mybatis.**",
        "com.hu.hutool.**"})
public class HutoolApplication implements CommandLineRunner {

    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(HutoolApplication.class, args);
        BaseExceptionHandler bean = run.getBean(BaseExceptionHandler.class);
        log.info("bean :{}", bean);
    }

    @Override
    public void run(String... args) throws Exception {
        log.info("初始化完成会调用......... 搞一个线程池进来");

        ThreadPoolExecutorTest.getPoolConfig().getMyThreadPool().execute(() -> {
            log.info("执行自定义线程池中的线程：线程名称是:{}", Thread.currentThread().getName());
        });
        //启动定时任务
        CronUtil.start();

        XxlJobExecutor.registJobHandler("jobHandleSecond", new XxlJobHandleSecond());
    }
}
